<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
</head>
<body>

</body>
</html>

<script>
	function ean13(num){
		var arr=[];
		while(num){
			arr.unshift(num%10);
			num=parseInt(num/10);
		}
		//alert(arr);
		var sum_ou=0;
		var sum_ji=0;
		for(var i=0;i<arr.length;i++){
			if((i+1)%2==0){
				sum_ou+=arr[i];
			}else{
				sum_ji+=arr[i];
			}
		}

		var sum = sum_ji+sum_ou*3;

		sum = sum%10;
		if (sum==0) {
			return 0;
		}else{
			return 10-sum;
		}
	}

	document.write(ean13(690123456789));
</script>